Home:ALL Converter>CMake fails to find OpenCV installed via vcpkg under wsl (returns opencv for Windows Conda Environment)

CMake fails to find OpenCV installed via vcpkg under wsl (returns opencv for Windows Conda Environment)

Ask Time:2021-04-06T02:31:50         Author:DoubleSteakHouse

Json Formatter

So I am currently trying to get my CMake Project to build after installing packages via vcpkg for the first time. I am using WSL2 under Win10 with Ubuntu 20.04 for the project, but building throws the following:

philip@DESKTOP-2CHKCMO:/mnt/c/Users/phili/_Documents/Projects/pixelator$ cmake .
-- OpenCV ARCH: 
-- OpenCV RUNTIME: 
-- OpenCV STATIC: ON
CMake Warning at /mnt/c/Users/phili/anaconda3/Library/opencvConfig.cmake:140 (message):
  Found OpenCV Windows Pack but it has no binaries compatible with your
  configuration.

  You should manually point CMake variable OpenCV_DIR to your build of OpenCV
  library.
Call Stack (most recent call first):
  CMakeLists.txt:13 (find_package)


-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/c/Users/phili/_Documents/Projects/pixelator

This is my CMakeLists.txt:

cmake_minimum_required(VERSION 3.16)
project(pixelator LANGUAGES CXX)

#include("~/vcpkg/scripts/buildsystems/vcpkg.cmake")
set(CMAKE_TOOLCHAIN_FILE "~/vcpkg/scripts/buildsystems/vcpkg.cmake")

set(OpenCV_DIR "~/vcpkg/packages/opencv4_x64-linux/share/opencv")

find_package(protobuf CONFIG REQUIRED)
find_package(opencv CONFIG REQUIRED)
find_package(gflags CONFIG REQUIRED)

add_library(pixeling ${CMAKE_SOURCE_DIR}/source/pixeling.cpp)
target_link_libraries(pixeling ${OpenCV_LIBS})
add_executable(io ${CMAKE_SOURCE_DIR}/source/io.cpp)
target_link_libraries(io pixeling gflags)

The Folder is located in Windows10, but I am building via Ubuntu. Apparently CMake seems to ignore that I set the OpenCV_DIR and returns an openCV installation for my python anaconda environment (which is not located in wsl, but Windows), which it can't use. Also, I was under the impression that I would not even be required to set the OpenCV_DIR after linking the Toolchain file?

How do I get it to find the right openCV installation?

Author:DoubleSteakHouse,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/66957956/cmake-fails-to-find-opencv-installed-via-vcpkg-under-wsl-returns-opencv-for-win
yy